﻿(function () {
	rf.news.edit =
		{
			settings: {
				urls: {
					swf: null,
					uploader: null
				},
				vars: {
				},
				elements: {
					uploadify: '#uploadify',
					imgNews: '#img-news',
					tinymce: '#Description',
					hiddenImgNews: '#ImageUrl',
					refreshImageUrlSelector: '#refresh-image-url',
					staticImageUrlSelector: '#StaticImageUrl'
				}
			},

			init: function (settings) {
				$.extend(true, rf.news.edit.settings, settings);

				$(rf.news.edit.settings.elements.uploadify).uploadify({
					'swf': rf.news.edit.settings.urls.swf,
					'uploader': rf.news.edit.settings.urls.uploader,
					'buttonText' : 'Обзор...',
					'auto': true,
					'multi': false,
					'fileTypeDesc': 'Image Files',
					'fileTypeExts': '*.gif; *.jpg; *.png',
					//'fileSizeLimit': '100KB',
					'queueSizeLimit': '1',
					'onUploadSuccess': function (file, data, response) {
						refreshImageUrl(rf.news.edit.settings.elements.imgNews, data, 200, 200, function () {
							$(rf.news.edit.settings.elements.hiddenImgNews).val(data);
							resizeNiceScroll();
						});
					}
				});

				$(rf.news.edit.settings.elements.refreshImageUrlSelector).off("click").on("click", function () {
					refreshImageUrl(rf.news.edit.settings.elements.imgNews, $(rf.news.edit.settings.elements.staticImageUrlSelector).val(), 200, 200, function () {
						$(rf.news.edit.settings.elements.hiddenImgNews).val($(rf.news.edit.settings.elements.staticImageUrlSelector).val());
						resizeNiceScroll();
					});
					
				});

				tinymce.init({
					selector: rf.news.edit.settings.elements.tinymce,
					plugins: [
						"advlist autolink lists link image charmap print preview anchor",
						"searchreplace visualblocks code fullscreen",
						"insertdatetime media table contextmenu paste"
					],
					toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
				});
			}
		};
})();